package com.mike.rabbitmq;

import com.alibaba.fastjson.JSON;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.core.MessageProperties;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.amqp.rabbit.support.CorrelationData;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import java.util.HashMap;

/**
 * Hello world!
 *
 */
public class App 
{
    public static void main( String[] args )
    {
        ApplicationContext applicationContext = new ClassPathXmlApplicationContext("spring-rabbitmq.xml");
        RabbitTemplate template = (RabbitTemplate)applicationContext.getBean("testHeaderTemplate");
        HashMap<String,String> map = new HashMap<>();
        map.put("test","1");
        map.put("test2","2");
        CorrelationData correlationData = new CorrelationData();
//        correlationData.
        MessageProperties messageProperties = new MessageProperties();
        messageProperties.setHeader("header1","header1");
        messageProperties.setHeader("header2","header2");
        messageProperties.setHeader("header3","header3");
        Message message = new Message(JSON.toJSONString(map).getBytes(),messageProperties);

        template.convertAndSend(message);
        System.out.println("发送完成");
    }
}
